<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    public function index(){
        $this->display();
    }

    public function login(){
        $username = trim(I('post.uer'));
        $password = trim(I('post.pwd'));
        $a = M("users")-> where(array('username'=>$username,'password'=>$password)) -> find();
        $b = M("admin")-> where(array('adminname'=>$username,'password'=>$password)) -> find();
        if($a||$b){
            $this->success('登陆成功',U("Home/Index/index"));
              session('uid', $a['uid']);
              session('id', $b['id']);

            
        }
        else{
            $this->error('登陆失败',U("Home/Login/index"));
        }
    }

    public function loginout(){
        session('uid',null);
        $this->success('退出成功',U("Home/Login/index"));

    }

public function register(){
    $this->display();
}
public function submit(){
    $data['username'] = trim(I('post.username'));
    $data['password'] = trim(I('post.password'));
    $data['sex'] = trim(I('post.sex'));
    $data['birthday'] = trim(I('post.birthday'));
    $data['qq'] = trim(I('post.qq'));
    $data['tel'] = trim(I('post.tel'));
    $data['intro'] = trim(I('post.intro'));
    $upload = new \Think\Upload();// 实例化上传类
    $upload->maxSize = 3145728 ;// 设置附件上传大小
    $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    $upload->rootPath = './Public/images/pic/'; // 设置附件上传根目录
    $upload->autoSub = false;
    $info = $upload->uploadOne($_FILES['pic']);
    if(!$info) {// 上传错误提示错误信息
        $this->error($upload->getError());
    }
    $data['pic']=$info['savepath'].$info['savename'];
    $result=M('users')->where(array('username'=>$data['username']))->find();
    if($result)
        $this->error('用户名重复！', U("Login/register"));
    else{
        M('users')->add($data);
        $this->success('注册成功！',U('Login/index'));
        
    }
}

}